package com.yy.dao.db;

import android.database.sqlite.SQLiteDatabase;

/**
 * User: gongyongfeng2@yy.com
 * Date: 2020/7/3 11 :06
 */

public class BaseDaoFactory {
    private static final BaseDaoFactory ourInstance = new BaseDaoFactory();

    private SQLiteDatabase sqLiteDatabase;

    private String sqliteDatabasePath;

    public static BaseDaoFactory getOurInstance(){
        return ourInstance;
    }

    public BaseDaoFactory() {
        //新建数据库
//        Environment.getExternalStorageDirectory() + File.separator
        sqliteDatabasePath = "data/data/com.yy.hi.library/dao.db";
        sqLiteDatabase = SQLiteDatabase.openOrCreateDatabase(sqliteDatabasePath, null);
    }

    public <T> BaseDao<T> getBaseDao(Class<T> entityClass){
        BaseDao baseDao = null;
        try {
            baseDao = BaseDao.class.newInstance();
            baseDao.init(sqLiteDatabase, entityClass);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return baseDao;
    }
}
